-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve docs for collecting into Option
s
#56342
Conversation
r? @bluss (rust_highfive has picked a reviewer for you, use r? to override) |
/// | ||
/// let res: Option<Vec<u16>> = items | ||
/// .iter() | ||
/// .map(|x| x.checked_add(1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is an obvious function or should be explain more (or use the explicit impl of checked adding as it did previously)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems fine as it is, maybe it comes best together if we mention that checked_add/_sub
returns None on overflow, on this example or the next?
dde0d11
to
a8c3553
Compare
Changes the original example to use more idiomatic formatting as well as `.checked_add`. Also adds a second example to show a case where the `.collect` returns `None`.
a8c3553
to
2c0f011
Compare
Sorry, totally missed that comment, @bluss! Added this:
|
@bors r+ rollup Thanks! |
📌 Commit 2c0f011 has been approved by |
… r=bluss Improve docs for collecting into `Option`s Changes the original example to use more idiomatic formatting as well as `.checked_add`. Also adds a second example to show a case where the `.collect` returns `None`.
Rollup of 14 pull requests Successful merges: - #56188 (enum type instead of variant suggestion unification ) - #56342 (Improve docs for collecting into `Option`s) - #56916 (Fix mutable references in `static mut`) - #56917 (Simplify MIR generation for logical operations) - #56939 (Pin stabilization) - #56953 (Mark tuple structs as live if their constructors are used) - #56964 (Remove `TokenStream::JointTree`.) - #56966 (Correct strings for raw pointer deref and array access suggestions) - #57020 (Point to cause of `fn` expected return type) - #57032 (fix deprecation warnings in liballoc benches) - #57053 (Fix alignment for array indexing) - #57062 (Fix a comment) - #57067 (Stabilize min_const_unsafe_fn in 1.33) - #57078 (Ignore two tests on s390x) Failed merges: r? @ghost
Changes the original example to use more idiomatic formatting as well
as
.checked_add
. Also adds a second example to show a case where the.collect
returnsNone
.